home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / texinfo / info / general.h < prev    next >
C/C++ Source or Header  |  1994-01-28  |  3KB  |  82 lines

  1. /* general.h -- Some generally useful defines. */
  2.  
  3. /* This file is part of GNU Info, a program for reading online documentation
  4.    stored in Info format.
  5.  
  6.    Copyright (C) 1993 Free Software Foundation, Inc.
  7.  
  8.    This program is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2, or (at your option)
  11.    any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.    Written by Brian Fox (bfox@ai.mit.edu). */
  23.  
  24. #if !defined (_GENERAL_H_)
  25. #define _GENERAL_H_
  26.  
  27. extern void *xmalloc (), *xrealloc ();
  28.  
  29. #if defined (HAVE_UNISTD_H)
  30. #  include <unistd.h>
  31. #endif /* HAVE_UNISTD_H */
  32.  
  33. #if defined (HAVE_STRING_H)
  34. #  include <string.h>
  35. #else
  36. #  include <strings.h>
  37. #endif /* !HAVE_STRING_H */
  38.  
  39. #if !defined (savestring)
  40. #  define savestring(x) (char *)strcpy ((char *)xmalloc (1 + strlen (x)), x)
  41. #endif /* !savestring */
  42.  
  43. #define info_toupper(x) (islower (x) ? toupper (x) : x)
  44. #define info_tolower(x) (isupper (x) ? tolower (x) : x)
  45.  
  46. #if !defined (whitespace)
  47. #  define whitespace(c) ((c == ' ') || (c == '\t'))
  48. #endif /* !whitespace */
  49.  
  50. #if !defined (whitespace_or_newline)
  51. #  define whitespace_or_newline(c) (whitespace (c) || (c == '\n'))
  52. #endif /* !whitespace_or_newline */
  53.  
  54. #if !defined (__FUNCTION_DEF)
  55. #  define __FUNCTION_DEF
  56. typedef int Function ();
  57. typedef void VFunction ();
  58. #endif /* _FUNCTION_DEF */
  59.  
  60. /* Add POINTER to the list of pointers found in ARRAY.  SLOTS is the number
  61.    of slots that have already been allocated.  INDEX is the index into the
  62.    array where POINTER should be added.  GROW is the number of slots to grow
  63.    ARRAY by, in the case that it needs growing.  TYPE is a cast of the type
  64.    of object stored in ARRAY (e.g., NODE_ENTRY *. */
  65. #define add_pointer_to_array(pointer, idx, array, slots, grow, type) \
  66.   do { \
  67.     if (idx + 2 >= slots) \
  68.       array = (type *)(xrealloc (array, (slots += grow) * sizeof (type))); \
  69.     array[idx++] = (type)pointer; \
  70.     array[idx] = (type)NULL; \
  71.   } while (0)
  72.  
  73. #define maybe_free(x) do { if (x) free (x); } while (0)
  74.  
  75. #if !defined (HAVE_BZERO)
  76. #  define zero_mem(mem, length) memset (mem, 0, length)
  77. #else
  78. #  define zero_mem(mem, length) bzero (mem, length)
  79. #endif /* !BZERO_MISSING */
  80.  
  81. #endif /* !_GENERAL_H_ */
  82.